package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.EsDocService;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.domain.vo.EsDocQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "Es文档管理")
@RequestMapping("/esDoc")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;

    @PostMapping("/batchInsertDocs")
    @ApiOperation(value = "批量插入文档")
    public R<Boolean>  batchInsertDocs(@RequestBody List<EsDocInsertVo> esDocInsertVo){
        return esDocService.batchInsertDocs( esDocInsertVo);
    }

    @PostMapping("/queryDocs")
    @ApiOperation(value = "根据传入条件查询Es的文档数据")
    public R  queryDocs(@RequestBody EsDocQueryVo esDocInsertVo){
        return esDocService.queryDocs(esDocInsertVo);
    }

    @PostMapping("/deleteDocs")
    @ApiOperation(value = "根据传入条件删除Es的文档数据")
    public R  deleteDocs(@RequestParam("indexName") String indexName,@RequestParam("ids") List<String> ids){
        esDocService.batchInsertDocs(indexName,ids);
        return R.ok();
    }

    @GetMapping("/queryDocsSuggestions/{indexName}")
    @ApiOperation(value = "自动补全联想")
    public R queryDocsSuggestions(@PathVariable("indexName") String indexName,
                                  @RequestParam("keyWord") String keyWord,
                                  @RequestParam("suggestFiled") String suggestFiled){
        return esDocService.queryDocsSuggestions(indexName,keyWord,suggestFiled);
    }



}
